"""
鼠标操作
    在webdriver中，鼠标的操作一般通过ActionChains类来实现
    鼠标操作，单击，双击，右击，悬停，拖动，滚动
"""""
from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

path = Service(executable_path=r'C:\Users\Laptop\Desktop\thirty_one\chromedriver.exe')
driver = webdriver.Chrome(service=path)
driver.maximize_window()
driver.implicitly_wait(10)
# driver.get('https://sahitest.com/demo/clicks.htm')
action = webdriver.ActionChains(driver) # 初始化ActionChains类
#
# action.double_click(driver.find_element(By.XPATH,'/html/body/form/input[2]')).perform() # 双击的操作
# driver.get_screenshot_as_file('鼠标双击.png')
#
# action.context_click(driver.find_element(By.XPATH,'/html/body/form/input[4]')).perform() # 右击的操作
# driver.get_screenshot_as_file('鼠标右击.png')


# driver.get('https://baidu.com')
# action.move_to_element(driver.find_element(By.XPATH,'//*[@id="s-usersetting-top"]')).perform() # 悬停操作
# driver.get_screenshot_as_file('鼠标悬停.png')

# driver.get('https://sahitest.com/demo/dragDropMooTools.htm')
# source = driver.find_element(By.ID,'dragger') # 你要拖动的对象
# target = driver.find_element(By.XPATH,'/html/body/div[2]') # 你要拖动到哪个对象上
# action.drag_and_drop(source, target).perform() # 拖动操作
# driver.get_screenshot_as_file('鼠标拖动.png')
'''滚动操作'''
# 需要借助js脚本去模拟滚动的操作
driver.get('https://bing.com')
sleep(3)
js = 'window.scrollTo(0,10000)'
driver.execute_script(js) # 滚动操作
sleep(3)
driver.get_screenshot_as_file('鼠标滚动.png')
